﻿using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

#if UNITY_EDITOR
namespace Panty.QF
{

    public static class HandlesExtensions
    {
        // Fix编码

        /// <summary>
        /// 在Scene视图绘制2D胶囊体
        /// </summary>
        /// <param name="center">中心点</param>
        /// <param name="size">大小</param>
        /// <param name="dir">方向</param>
        public static void DrawCapsule2D(Vector3 center, Vector2 size, CapsuleDirection2D dir)
        {
            size.Set(Mathf.Abs(size.x), Mathf.Abs(size.y));

            if (dir == CapsuleDirection2D.Vertical)
            {
                if (size.y < size.x)
                    size.Set(size.x, size.x);

                Handles.DrawWireArc(new Vector3(0, (size.y - size.x) / 2) + center, -Vector3.forward, Vector3.left, 180, size.x / 2);

                Handles.DrawLine(new Vector3(-size.x / 2, -(size.y - size.x) / 2) + center, new Vector3(-size.x / 2, (size.y - size.x) / 2));
                Handles.DrawLine(new Vector3(size.x / 2, -(size.y - size.x) / 2) + center, new Vector3(size.x / 2, (size.y - size.x) / 2));

                Handles.DrawWireArc(new Vector3(0, -(size.y - size.x) / 2) + center, Vector3.forward, Vector3.left, 180, size.x / 2);
            }
            else
            {
                if (size.x < size.y)
                    size.Set(size.y, size.y);

                Handles.DrawWireArc(new Vector3(-(size.x - size.y) / 2, 0) + center, -Vector3.forward, Vector3.down, 180, size.y / 2);

                Handles.DrawLine(new Vector3(-(size.x - size.y) / 2, -size.y / 2) + center, center + new Vector3((size.x - size.y) / 2, -size.y / 2));
                Handles.DrawLine(new Vector3(-(size.x - size.y) / 2, size.y / 2) + center, center + new Vector3((size.x - size.y) / 2, size.y / 2));

                Handles.DrawWireArc(new Vector3((size.x - size.y) / 2, 0) + center, Vector3.forward, Vector3.down, 180, size.y / 2);
            }
        }

    }
}

#endif